<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page import="java.security.Principal"%>
<%@ page import="com.conversationboard.model.StyleSheets"%>
<%@ page import="com.conversationboard.view.MainMenu"%>
<%@ page import="com.conversationboard.tree.Node"%>
<%@ page import="com.conversationboard.tree.Folders"%>
<%@ page import="java.util.List"%>
<%@ page import="com.conversationboard.controller.confirm.Confirm"%>
<%@ page import="com.conversationboard.model.Board"%>
<%@ page import="com.conversationboard.model.Boards"%>
<%@ page import="com.conversationboard.model.User"%>

<%
	Principal principal = request.getUserPrincipal();
	User user = User.get(principal);
	List<Node> folders = Folders.getInstance().getRoot().getChildFolders(user, true);
	List<Node> boardNodes = Folders.getInstance().getRoot().getChildBoards(user, true);
	List<Node> linkNodes = Folders.getInstance().getRoot().getChildLinks(user, true);
	String treeDrawing = Folders.getInstance().drawTree(user, true);
	List<Board> boards = Boards.getAuthorisedBoards(user, true); 

	request.setAttribute("treeDrawing", treeDrawing);
	request.setAttribute("user", user);
	request.setAttribute("boards", boards);
	request.setAttribute("boardNodes", boardNodes);
	request.setAttribute("linkNodes", linkNodes);
	request.setAttribute("folders", folders);

	String key = Confirm.getKey(request.getUserPrincipal().getName());
%>

<html>

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<title>Board Structure</title>
	<link rel="stylesheet"title="Conversation Board" type="text/css" href="${contextPath}/Stylesheets/<%=StyleSheets.getStyleSheetFileName(request.getCookies())%>">
</head>

<body>

	<%= MainMenu.display(principal) %>

	<div class="headingblock">
		<h1>Board Structure</h1>
	</div>

	<div class="mainblock">

		<div class="formsection">
			<p>This page contains a variety of functions to let you restructure how the boards look, in terms of their folder
			   structure. Note that the software will let you place a board in more than one place. If you want a board in
			   only a single place, you must remove other instances of it yourself.</p>

			<div class="formsectionlight">
				<pre>${treeDrawing}</pre>
			</div>

			<br />

			<!-- Creating a Folder -->
	
			<form class="formsectionlight" action="${contextPath}/Admin/AdminCreateFolderControllerServlet" method="post">
			
				<h2>Create a New Folder</h2>
				<%= key %>
			
			 	<label for="name"><strong>Folder name:</strong></label>
			 	<input name="name" class="smalltextbox" type="text" size=100 /><br /><br />

			 	<label for="description"><strong>Folder description:</strong></label>
			 	<input name="description" class="smalltextbox" type="text" size=100 /><br /><br />
	
			 	<label for="parentFolder"><strong>Create within:</strong></label>
			
				<select name="parentFolder">
					<option value="0" selected>Root Folder
					<c:forEach var="folder" items="${folders}">
						<option value="${folder.nodeId}">${folder.folderName}
					</c:forEach>
				</select>
						
				<br /><br />
			 	<input type="submit" value="      Create Folder      " />
			
			</form>

			<!-- Placing a board in a folder -->

			<form class="formsectionlight" action="${contextPath}/Admin/AdminPlaceBoardInFolderControllerServlet" method="post">
			
				<h2>Put a Board in a Folder</h2>
				<%= key %>
			
			 	<label for="parentFolder"><strong>Put board:</strong></label>
			
				<select name="boardId">
					<c:forEach var="board" items="${boards}">
						<option value="${board.boardId}">${board.name}
					</c:forEach>
				</select>
	
			 	<label for="parentFolder"><strong>in folder:</strong></label>
			
				<select name="parentFolder">
					<option value="0" selected>Root Folder
					<c:forEach var="folder" items="${folders}">
						<option value="${folder.nodeId}">${folder.folderName}
					</c:forEach>
				</select>
				
				<br /><br />

				<label for="move"><strong>Remove Existing Instances of this Board:</strong></label>
				<input title="Because a board can be in more than one place in the tree, checking this box will remove all instances of the board prior to moving it to its new parent folder."
				       type="checkbox" name="move" value="true" CHECKED />
						
				<br /><br />
			 	<input type="submit" value="      Put Board in Selected Folder      " />
			
			</form>

			<!-- Placing a link in a folder -->

			<form class="formsectionlight" action="${contextPath}/Admin/AdminMoveLinkControllerServlet" method="post">
			
				<h2>Put a Link in a Folder</h2>
				<%= key %>
			
			 	<label for="parentFolder"><strong>Put link:</strong></label>
			
				<select name="nodeId">
					<c:forEach var="link" items="${linkNodes}">
						<option value="${link.nodeId}">${link.linkDescription}
					</c:forEach>
				</select>
	
			 	<label for="parentFolder"><strong>in folder:</strong></label>
			
				<select name="parentFolder">
					<option value="0" selected>Root Folder
					<c:forEach var="folder" items="${folders}">
						<option value="${folder.nodeId}">${folder.folderName}
					</c:forEach>
				</select>
				
				<br /><br />

				<label for="move"><strong>Remove Existing Instances of this Link:</strong></label>
				<input title="Because a link can be in more than one place in the tree, checking this box will remove all instances of the link prior to moving it to its new parent folder."
				       type="checkbox" name="move" value="true" CHECKED />
						
				<br /><br />
			 	<input type="submit" value="      Put Link in Selected Folder      " />
			
			</form>


			<!-- Removing a board from a folder -->

			<form class="formsectionlight" action="${contextPath}/Admin/AdminRemoveNodeFromFolderControllerServlet" method="post">
			
				<h2>Remove a Board</h2>
				<%= key %>
			
			 	<label for="nodeId"><strong>Remove Board:</strong></label>
			
				<select name="nodeId">
					<c:forEach var="boardNode" items="${boardNodes}">
						<option value="${boardNode.nodeId}">${boardNode.boardObject.name} (Node ID: ${boardNode.nodeId})
					</c:forEach>
				</select>
	
				<br /><br />
			 	<input type="submit" value="      Remove Board      " />
			
			</form>

			<!-- Removing a link from a folder -->

			<form class="formsectionlight" action="${contextPath}/Admin/AdminRemoveNodeFromFolderControllerServlet" method="post">
			
				<h2>Remove a Link</h2>
				<%= key %>
			
			 	<label for="nodeId"><strong>Remove Link:</strong></label>
			
				<select name="nodeId">
					<c:forEach var="linkNode" items="${linkNodes}">
						<option value="${linkNode.nodeId}">${linkNode.linkDescription} (Node ID: ${linkNode.nodeId})
					</c:forEach>
				</select>
	
				<br /><br />
			 	<input type="submit" value="      Remove Link      " />
			
			</form>


			<!-- Editing a Folder's Name -->
	
			<form class="formsectionlight" action="${contextPath}/Admin/AdminEditFolderNameControllerServlet" method="post">
			
				<h2>Edit a Folder's Name</h2>
				<%= key %>
			
			 	<label for="parentFolder"><strong>Change this folder's name:</strong></label>
			
				<select name="nodeId">
					<c:forEach var="folder" items="${folders}">
						<option value="${folder.nodeId}">${folder.folderName}
					</c:forEach>
				</select>
				
			 	<label for="name"><strong>to:</strong></label>
			 	<input name="name" class="smalltextbox" type="text" size=100 /><br /><br />
						
				<br /><br />
			 	<input type="submit" value="      Update Name      " />
			
			</form>


			<!-- Editing a Folder's Description -->
	
			<form class="formsectionlight" action="${contextPath}/Admin/AdminEditFolderDescriptionControllerServlet" method="post">
			
				<h2>Edit a Folder's Description</h2>
				<%= key %>
			
			 	<label for="parentFolder"><strong>Change this folder's description:</strong></label>
			
				<select name="nodeId">
					<c:forEach var="folder" items="${folders}">
						<option value="${folder.nodeId}">${folder.folderName}
					</c:forEach>
				</select>
				
			 	<label for="description"><strong>to:</strong></label>
			 	<input name="description" class="smalltextbox" type="text" size=100 /><br /><br />
						
				<br /><br />
			 	<input type="submit" value="      Update Description      " />
			
			</form>

			<!-- Editing a Link's Description -->
	
			<form class="formsectionlight" action="${contextPath}/Admin/AdminEditLinkDescriptionControllerServlet" method="post">
			
				<h2>Edit a Link's Description</h2>
				<%= key %>
			
			 	<label for="parentFolder"><strong>Change this link's description:</strong></label>
			
				<select name="nodeId">
					<c:forEach var="linkNode" items="${linkNodes}">
						<option value="${linkNode.nodeId}">${linkNode.linkDescription}
					</c:forEach>
				</select>
				
			 	<label for="description"><strong>to:</strong></label>
			 	<input name="description" class="smalltextbox" type="text" size=100 /><br /><br />
						
				<br /><br />
			 	<input type="submit" value="      Update Description      " />
			
			</form>
			
			<!-- Editing a Link's Target -->
	
			<form class="formsectionlight" action="${contextPath}/Admin/AdminEditLinkTargetControllerServlet" method="post">
			
				<h2>Edit a Link's HTML</h2>
				<%= key %>
			
			 	<label for="parentFolder"><strong>Change this link's target:</strong></label>
			
				<select name="nodeId">
					<c:forEach var="linkNode" items="${linkNodes}">
						<option value="${linkNode.nodeId}">${linkNode.linkDescription}
					</c:forEach>
				</select>
				
			 	<label for="linkHtml"><strong>to:</strong></label>
			 	<input name="linkHtml" class="smalltextbox" type="text" size=100 /><br /><br />
						
				<br /><br />
			 	<input type="submit" value="      Update HTML      " />
			
			</form>
			
			<!-- Move a board -->

			<form class="formsectionlight" action="${contextPath}/Admin/AdminMoveBoardControllerServlet" method="post">
			
				<h2>Move a Board</h2>
				<%= key %>
			
			 	<label for="fromNodeId"><strong>Move Board:</strong></label>
			
				<select name="fromNodeId">
					<c:forEach var="boardNode" items="${boardNodes}">
						<option value="${boardNode.nodeId}">${boardNode.boardObject.name}
					</c:forEach>
				</select>
	
			 	<label for="position"><strong>To:</strong></label>

				<select name="position">
					<option value="Before">Before
					<option value="After">After
				</select>

				<br /><br />

			 	<label for="toNodeId"><strong>This Board:</strong></label>

				<select name="toNodeId">
					<c:forEach var="boardNode" items="${boardNodes}">
						<option value="${boardNode.nodeId}">${boardNode.boardObject.name}
					</c:forEach>
				</select>
				
				<br /><br />

			 	<input type="submit" value="      Move Board      " />
			
			</form>

			<!-- Create an External Link -->
	
			<form class="formsectionlight" action="${contextPath}/Admin/AdminCreateExternalLinkControllerServlet" method="post">
			
				<h2>Create External Link</h2>
				<%= key %>
			
			 	<label for="linkHtml"><strong>Link HTML:</strong></label>
			 	<input name="linkHtml" class="smalltextbox" type="text" size=100 /><br /><br />

			 	<label for="description"><strong>Description</strong></label>
			 	<input name="description" class="smalltextbox" type="text" size=100 /><br /><br />
						
			 	<input type="submit" value="      Create Link      " />
			
			</form>

			
		</div>
	</div>

	<!--<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>-->
	<!--<script type="text/javascript">_uacct = "UA-1148679-1";urchinTracker();</script>--> 

</body>
</html>